package org.atovio.coolexam.mapper;

import org.apache.ibatis.annotations.*;
import org.atovio.coolexam.entity.ExamPaper;

import java.util.List;
import java.util.Map;

public interface ExamPaperMapper {

    @Insert("""
            insert into t_exam_paper (id, name, subject_id, score, question_count, suggest_time, 
            limit_start_time, limit_end_time, create_user, create_time)
            values (null, #{name}, #{subjectId}, #{score},#{questionCount},#{suggestTime},
            #{limitStartTime},#{limitEndTime},#{createUser},#{createTime});
            """)
    int insert(ExamPaper examPaper);

    @Select("select * from t_exam_paper;")
    List<ExamPaper> selectAll();

    @Select("select * from t_exam_paper where id = #{id}")
    ExamPaper selectById(Integer id);

    @Select("select * from t_exam_paper where name = #{name}")
    ExamPaper selectByName(String name);

    @Select("select * from t_exam_paper where name like concat('%', #{name}, '%')")
    List<ExamPaper> selectLikeName(String name);

    @Select("select * from t_exam_paper where subject_id = #{subjectId};")
    List<ExamPaper> selectBySubjectId(Integer subjectId);

    @Select("select * from t_exam_paper where create_user = #{createUser};")
    List<ExamPaper> selectByCreateUser(Integer createUser);

    /**
     * 根据自定义条件查询记录条数
     *
     * @param criteria 自定义条件
     * @return 记录条数
     */
    int selectCountSelective(@Param("criteria") Map<String, Object> criteria);

    List<ExamPaper> selectSelective(@Param("criteria") Map<String, Object> criteria);

    @Update("update t_exam_paper set name = #{name} where id = #{id};")
    int updateNameById(Integer id, String name);

    @Update("update t_exam_paper set subject_id = #{subjectId} where id = #{id};")
    int updateSubjectIdById(Integer id, Integer SubjectId);

    @Update("update t_exam_paper set question_count = #{questionCount} where id = #{id};")
    int updateQuestionCountById(Integer id, Integer questionCount);

    @Delete("delete from t_exam_paper where id = #{id};")
    int deleteById(Integer id);
}
